<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
   class Main extends Admin_Controller
   {
      function __construct()
      {
         parent::__construct();
       
      }
      function index()
      {
         
         $this->load->view('admin/admin_login');
      }
      function login()
      {
      	$post=$this->input->post(NULL,TRUE);
      	if($this->_code_check($post['yzm']))
      	{
      		if($post['opt']=='ajax')
         	{
	      		$user=trim($post['name']);
	      		$pwd =md5(trim($post['pwd']).MD5PLUS);
	      		$time=time();
	      		$this->load->model('User_model');
	      		$res=$this->User_model->login($user,$pwd);
      		    if($res)
      		    {
      		     	if($post['auto_login']=='true')
			      	{
			      		$this->session->set_userdata('user',$user);
      		    	    $this->session->set_userdata('password',$pwd);
			      	}
      		    	$login_update = array(
      		    	      'lastloginip'=>$this->input->ip_address(),
      		    	      'lastlogintime'=>time(),
      		    	);
      		    	$user_data= array(
      		    	      'lastloginip'=>$this->input->ip_address(),
      		    	      'lastlogintime'=>time(),
      		    	      'adminname'=>$user,
      		    	);
      		    	 $this->session->set_userdata($user_data);
      		    	 $this->User_model->update($res['adminid'],$login_update);
      		    	 echo 'true';
      		    }
      		    else
      		    echo USER_OR_PWD_ERROR;
      	    }
      	}else
      	{
      		echo YZM_ERROR;
      	}
      }
       
   	function _code_check($yzm_code)
	{
		$sess_code = $this->session->userdata('sess_code');
		if(strtolower($yzm_code) != $sess_code)
		{
			return FALSE;
		}
		else
		{
			return TRUE;
		}
	}
	function login_index()
	{
		$data['adminname']=$this->session->userdata('adminname');
		$data['sys_info']=get_sysinfo();
		$this->load->view('admin/main',$data);
	}
    function system_set()
    {
    	$this->load->view('admin/system_set');
    }

    function sys_pwd()
    {
    	$this->load->view('admin/sys_pwd');
    }
    function login_out()
    {
    	
    	//redirect('admin/main/login');
    }
   }
?>   